package com.cf.r1042_ak;

import java.io.*;

public class e {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        in.nextToken();
        int T = (int) in.nval;
        while (T-- > 0) {
            in.nextToken(); int n = (int) in.nval;
            long[] a = new long[n + 1];
            long[] b = new long[n + 1];
            for (int i = 1; i <= n; i++) { in.nextToken(); a[i] = (long) in.nval; }
            for (int i = 1; i <= n; i++) { in.nextToken(); b[i] = (long) in.nval; }
            if (a[n] != b[n]) {
                out.println("No");
                continue;
            }

            long cur = a[n];
            boolean ans = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] == b[i]) {
                    cur = a[i];
                } else if ((a[i] ^ cur) == b[i]) {
                    cur = a[i] ^ cur;
                } else if (((a[i] ^ a[i + 1]) == b[i])) {
                    cur = a[i] ^ a[i + 1];
                } else {
                    ans = false;
                    break;
                }
            }

            out.println(ans ? "Yes" : "No");

        }
        out.flush();
        out.close();
        br.close();
    }
}
